package zhao.lulu.mapper;



import org.apache.ibatis.annotations.*;
import pojo.Emp;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    //根据ID删除员工
    @Delete("delete from emp where id = #{id}") // #{id} : 性能更高 , 更加安全(防止SQL注入)
    public void delete(Integer id);


    //插入员工数据  -----> 参数时实体对象 : #{属性名}  *****
    @Options(useGeneratedKeys = true, keyProperty = "id") // 获取到返回的主键 , 并且把返回的主键封装 emp 对象的id属性
    @Insert("insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            " values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);


    //更新数据
//    @Update("update emp set username=#{username} , password=#{password}, name=#{name},gender=#{gender},image=#{image},job=#{job},entrydate=#{entrydate}," +
//            " dept_id=#{deptId},update_time=#{updateTime} where id = #{id}")
    public void update(Emp emp);


    //根据ID查询数据

    //A. 起别名
//    @Select("select id, username, password, name, gender, image, job, entrydate, " +
//            " dept_id deptId , create_time createTime , update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);


    //B. 手动封装
//    @Select("select * from emp where id = #{id}")
//    @Results({
//        @Result(column = "dept_id", property = "deptId"),
//        @Result(column = "create_time", property = "createTime"),
//        @Result(column = "update_time", property = "updateTime"),
//    })
//    public Emp getById(Integer id);

    @Select("select * from emp where id = #{id}")
    public Emp getById(Integer id);


    //根据条件查询
    //@Select("select * from emp where name like '%${name}%' and gender = #{gender} and entrydate between #{min} and #{max}")
    //@Select("select * from emp where name like concat('%',#{name},'%') and gender = #{gender} and entrydate between #{min} and #{max}")
    public List<Emp> list(String name, Short gender, LocalDate min, LocalDate max);


    //批量删除 delete from emp where id in(18,19,20)
    public void deleteIds(List<Integer> ids);

}
